home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11283 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: spock.asic.sc.ti.com!usenet
  2. From: "Billy N. Patton" <bpatton@asic.sc.ti.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help: File counting lines
  5. Date: Wed, 13 Mar 1996 12:22:25 -0600
  6. Organization: Texas Instruments, Inc.
  7. Message-ID: <31471261.106A@asic.sc.ti.com>
  8. References: <4hni12$qst@bolivia.it.earthlink.net> <4huog1$t8s@news.axess.com>
  9. NNTP-Posting-Host: bily-linux.asic.sc.ti.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (WinNT; I)
  14. CC: bpatton@asic.sc.ti.com
  15.  
  16. Kamikaze wrote:
  17. > brunop@earthlink.net (Peter Bruno) wrote:
  18. > >Does anyone have any suggestions on a fast way to count the number of lines in
  19. > >a ASCII file.  Each line is terminted by a <enter> and all I need to do is
  20. > >count the number of lines (records) in the file.
  21. > >The way I've been doing it is by:  fgets(row, 128, File); count++;
  22. > >however, if the line is longer then 128 characters this does not work and it
  23. > >would seem that there must be a better way of doing it anyway... perhaps by
  24. > >incrementing the pointer until EOF??
  25. > >Any assistance would be greatly appreciated...
  26. > >Thanx,
  27. > >Peter Bruno
  28. > >brunop@earthlink.net
  29. > Yeah use the stream objects, like this
  30. > ifstream in;
  31. > int count = 0;
  32. > char buffer[BUFFER_SIZE );
  33. > in = open( name_of_file );
  34. > if ( !in.bad() )
  35. > {
  36. >         while ( !in.eof() )
  37. >         {
  38. >         getline( buffer, sizeof( buffer ) );
  39. >         count++;
  40. >         }
  41. >         in.close();
  42. > }
  43. > Something like this, you get the picture.
  44.  
  45. Get the gnu stuff and do :
  46. wc -l file_name
  47.